View on GitHub

csc263

Notes for CSC263 - Data Structures and Analysis

Back to index

Dynamic Tables

table T, $\vert T\vert $ denotes max number of items that can be stored

Operations

let $n = \text{# of items currently stored in }T$, let $\displaystyle \alpha(T) = \frac{n}{\vert T\vert }$

insert using table doubling

if T = [a, b, c, d] and $\vert T\vert = 4$, then insert(T, e) results in T = [a, b, c, d, e, _, _, _] and $\vert T\vert = 8$

Aggregate analysis

Suppose n items need to be inserted into empty table, then following table doubles happen:

T = [a]

T = [a, b]

T = [a, b, c, d]

...

Each double takes $\mathcal O(\vert T\vert )$ time and table needs to be doubled for every power of 2 that is $\leq n$, so inserting $n$ items takes $\displaystyle \mathcal O \left(n + \sum_{i = 1}^{\lfloor \log_2(n) \rfloor} 2^i \right)$ time

$\displaystyle \mathcal O \left(n + \sum_{i = 1}^{\lfloor \log_2(n) \rfloor} 2^i \right) = \mathcal O \left( n + 2^{\lfloor\log_2(n) \rfloor + 1} \right) = \mathcal O(n)$

Accounting analysis

delete with table shrinking

Naive approach: halve table when $\alpha(T) = \frac{1}{2}$

Better approach: halve table when $\alpha(T) = \frac{1}{4}$ - amortized analysis

Charging scheme: